/*
https://leetcode-cn.com/problems/my-calendar-ii/solution/wo-de-ri-cheng-an-pai-biao-ii-by-leetcode/
 */
import java.util.Map;
import java.util.TreeMap;

public class Solution731 {

    TreeMap<Integer,Integer> treeMap=new TreeMap<>();

    public Solution731() {

    }

    public boolean book(int start, int end) {
        treeMap.put(start,treeMap.getOrDefault(start,0)+1);
        treeMap.put(end,treeMap.getOrDefault(end,0)-1);
        int cur=0;
        for (Map.Entry<Integer, Integer> entry : treeMap.entrySet()) {
            cur+=entry.getValue();
            if (cur>2){
                treeMap.put(start,treeMap.getOrDefault(start,0)-1);
                treeMap.put(end,treeMap.getOrDefault(end,0)+1);
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Solution731 solution731=new Solution731();
        System.out.println(solution731.book(10, 20));
        System.out.println(solution731.book(50, 60));
        System.out.println(solution731.book(10, 40));
        System.out.println(solution731.book(5, 15));
        System.out.println(solution731.book(5, 10));
        System.out.println(solution731.book(25, 55));
    }
}
